package com.common.frame.listener


import android.view.View
import androidx.drawerlayout.widget.DrawerLayout

class DrawerListener(callback: ListenerBuilder.() -> Unit) : DrawerLayout.DrawerListener {
    val listener = ListenerBuilder().also(callback)
    override fun onDrawerStateChanged(newState: Int) {
        listener.onDrawerStateChanged?.invoke(newState)
    }

    override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
        listener.onDrawerSlide?.invoke(drawerView, slideOffset)
    }

    override fun onDrawerClosed(drawerView: View) {
        listener.onDrawerClosed?.invoke(drawerView)
    }

    override fun onDrawerOpened(drawerView: View) {
        listener.onDrawerOpened?.invoke(drawerView)
    }

    class ListenerBuilder {
        internal var onDrawerStateChanged: ((newState: Int) -> Unit)? = null
        internal var onDrawerSlide: ((drawerView: View, slideOffset: Float) -> Unit)? = null
        internal var onDrawerClosed: ((drawerView: View) -> Unit)? = null
        internal var onDrawerOpened: ((drawerView: View) -> Unit)? = null
        fun onDrawerStateChanged(action: (newState: Int) -> Unit) {
            onDrawerStateChanged = action
        }

        fun onDrawerSlide(action: (drawerView: View, slideOffset: Float) -> Unit) {
            onDrawerSlide = action
        }

        fun onDrawerClosed(action: (drawerView: View) -> Unit) {
            onDrawerClosed = action
        }

        fun onDrawerOpened(action: (drawerView: View) -> Unit) {
            onDrawerOpened = action
        }
    }
}